package com.heima.admin.service.Impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.admin.mapper.ChannelMapper;
import com.heima.admin.service.ChannelService;

import com.heima.api.IArticleClient;
import com.heima.api.admin.IUserClient;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.wemedia.dtos.WmChannelDto;
import com.heima.model.wemedia.pojos.WmChannel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ChannelServiceImpl extends ServiceImpl<ChannelMapper, WmChannel> implements ChannelService {

    @Autowired
    private IUserClient iUserClient;
    @Autowired
    private IArticleClient articleClient;



    @Override
    public ResponseResult delectChannel(Integer id) {

        return  iUserClient.delectChannel(id);


    }

    @Override
    public ResponseResult list(WmChannelDto wmChannelDto) {
        return iUserClient.list(wmChannelDto);
    }

    @Override
    public ResponseResult insert(WmChannel wmChannel) {
        return iUserClient.insert(wmChannel);
    }

    @Override
    public ResponseResult update(WmChannel wmChannel) {
        if((articleClient.queryChanner(wmChannel)==0)){
            iUserClient.update(wmChannel);
        }else {
            return ResponseResult.errorResult(500,"频道已被引用");
        }
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);



    }
}
